package sm.policy;

public class FreqAdaptPolicy {
	
	
	public FreqAdaptPolicy(){
		
	}
	public synchronized long checkFreq(byte energyCategory){
		 long adaptedSampleFreq = 0; 
		 switch (energyCategory) {
	       case 0:  adaptedSampleFreq = this.adaptFreq1(); break;
           case 1:  adaptedSampleFreq = this.adaptFreq1(); break;
           case 2:  adaptedSampleFreq = this.adaptFreq2(); break;
           case 3:  adaptedSampleFreq = this.adaptFreq2(); break;
           default: System.out.println("Invalid energy category");break;
			 }
		 return adaptedSampleFreq;		
	}
	public synchronized long adaptFreq1(){
		int battLevel = this.getBatteryLevel();
		long sampleFreq = 0;
		if (battLevel > 70){
				sampleFreq = 800;
			} else if (battLevel > 50){
					sampleFreq = 25000;
				} else if (battLevel > 30){
						sampleFreq = 50000;
					} else if (battLevel < 31){
							sampleFreq = 0;
						}
		return sampleFreq;
	}
	public synchronized int getBatteryLevel(){
		return 75;
	}
	public synchronized long adaptFreq2(){
		int battLevel = this.getBatteryLevel();
		long sampleFreq = 0;
		if (battLevel > 70){
				sampleFreq = 1000;
			} else if (battLevel > 50){
					sampleFreq = 40000;
				} else if (battLevel > 30){
						sampleFreq = 100000;
					} else if (battLevel < 31){
							sampleFreq = 0;
						}
		return sampleFreq;
		
	}
	

}
